﻿namespace NetByDocker.Filters;

/// <summary>
/// 自定义startup的Filter
/// </summary>
public class CustomerStartupFilter : IStartupFilter
{
    private readonly ILogger<CustomerStartupFilter> _logger;
    private readonly IConfiguration _configuration;

    public CustomerStartupFilter(ILogger<CustomerStartupFilter> logger, IConfiguration configuration)
    {
        _logger = logger;
        _configuration = configuration;
    }

    public Action<IApplicationBuilder> Configure(Action<IApplicationBuilder> next)
    {
        return builder =>
        {
            _logger.LogInformation("SetupMiddlewares后的一些任务");
            Execute();
            next(builder);
        };
    }

    private void Execute()
    {
#if !DEBUG
        _logger.LogInformation("---------开始展示环境变量");
        foreach (var c in _configuration.AsEnumerable())
        {
            _logger.LogInformation("---------" + c.Key + " = " + c.Value);
        }

        _logger.LogInformation("---------结束展示环境变量");
#endif
    }
}